<template>
  <div>
    <van-image :src="imageStr" @click="getKaptcha" />
  </div>
</template>

<script>
import { awaitWrapper, throttle } from '@/utils/common'
export default {
  data() {
    return {
      key: '',
      imageStr: ''
    }
  },

  created() {
    this.getKaptcha()
  },
  methods: {
    getKaptcha: throttle(async function() {
      const [error, result] = await awaitWrapper(createKaptcha())
      if (result) {
        this.imageStr = 'data:image/png;base64,' + result.imageStr
        this.key = result.key
        this.imageCodeShow = true
      } else {
        error.respMsg && this.$toast(error.respMsg)
      }
    })
  }
}
</script>

<style lang="less" scoped>
</style>
